
<style scoped>
.c-s-dl-li ul li:visited {
  background-color: white;
  color: brown;
}
.img-responsive {
  width: 267.5px;
  height: 150px;
}
.active {
 color: rgb(234, 86, 46)
}
/* .c-s-dl-li {
  width: inherit;
  height: 40px;
} */
</style>
<template>
  <div id="aCoursesList" class="bg-fa of">
    <!-- /课程列表 开始 -->
    <section class="container">
      <header class="comm-title">
        <h2 class="fl tac">
          <span class="c-333">全部课程</span>
        </h2>
      </header>
      <section class="c-sort-box">
        <section class="c-s-dl">
          <dl>
            <dt>
              <span class="c-999 fsize14">课程类别</span>
            </dt>
            <dd class="c-s-dl-li">
              <ul class="clearfix">
                <li>
                  <span title="全部" href="" @click="conditionParent(null)">全部</span>
                </li>
                <!-- <li v-for="subjectParent in subjectParentList" :key="subjectParent.id">
                  <a :title="subjectParent.title" href="javascript:void(0);" v-text="subjectParent.title" @click="conditionParent(subjectParent)"></a>
                </li> -->
                <li v-for="(item,index) in subjectParentList" v-bind:key="index">
                  <a :title="item.title" href="javascript:void(0);" @click="conditionParent(item,index)" :class="{active:oneIndex==index}">{{item.title}}</a>
                </li>
              </ul>
            </dd>
          </dl>
          <dl>
            <dt>
              <span class="c-999 fsize14"></span>
            </dt>
            <dd class="c-s-dl-li">
              <ul class="clearfix">
                <li v-for="(subject, index) in subjectList" :key="subject.id">
                  <a :title="subject.title" href="javascript:void(0);" v-text="subject.title" @click="conditionChild(subject, index)" :class="{active:twoIndex==index}"></a>
                </li>
              </ul>
            </dd>
          </dl>
          <div class="clear"></div>
        </section>
        <div class="js-wrap">
          <section class="fr">
            <span class="c-ccc">
              <i class="c-master f-fM">1</i>/
              <i class="c-666 f-fM">1</i>
            </span>
          </section>
          <section class="fl">
            <ol class="js-tap clearfix">
              <li :class="{'current bg-orange':courseQueryVo.gmtCreateSort}">
                <a style="text-decoration:none;" title="最新" href="javascript:void(0);" @click="searchGmtCreate()">最新
                <span :class="{hide:courseQueryVo.gmtCreateSort}">↓</span>
                </a>
              </li>
              <li :class="{'current bg-orange':courseQueryVo.buyCountSort}">
                <a style="text-decoration:none;" title="销量" href="javascript:void(0);" @click="searchBuyCount()">销量
                <span :class="{hide:courseQueryVo.buyCountSort}">↓</span>
                </a>
              </li>
              <li :class="{'current bg-orange':courseQueryVo.priceSort}">
                <a style="text-decoration:none;" title="价格" href="javascript:void(0);" @click="searchPrice()">价格&nbsp;
                  <span :class="{hide:courseQueryVo.priceSort}">↓</span>
                </a>
              </li>
            </ol>
          </section>
        </div>
        <div class="mt40">
          <!-- /无数据提示 开始-->
          <section class="no-data-wrap" v-if="courseList==null || courseList.length == 0">
            <em class="icon30 no-data-ico">&nbsp;</em>
            <span class="c-666 fsize14 ml10 vam">没有相关数据，小编正在努力整理中...</span>
          </section>
          <!-- /无数据提示 结束-->
          <article class="comm-course-list" v-else>
            <ul class="of" id="bna">
              <li v-for="course in courseList" :key="course.id">
                  <div class="cc-l-wrap">
                    <section class="course-img">
                      <img
                        :src="course.cover"
                        class="img-responsive"
                        :alt="course.title"
                      >
                      <div class="cc-mask">
                        <a :href="'/course/'+course.id" title="开始学习" class="comm-btn c-btn-1">开始学习</a>
                      </div>
                    </section>
                    <h3 class="hLh30 txtOf mt10">
                      <a :href="'/course/'+course.id" :title="course.title" v-text="course.title" class="course-title fsize18 c-333"></a>
                    </h3>
                    <section class="mt10 hLh20 of">
                      <span class="fr jgTag bg-green">
                        <i class="c-fff fsize12 f-fA" v-if="Number(course.price) === 0">免费</i>
                        <i class="c-fff fsize12 f-fA" v-else v-text="'¥'+course.price"></i>
                      </span>
                      <span class="fl jgAttr c-ccc f-fA">
                        <i class="c-999 f-fA" v-text="course.buyCount+'人购买'"></i>
                        |
                        <i class="c-999 f-fA"  v-text="course.viewCount+'人浏览'"></i>
                      </span>
                    </section>
                  </div>
                </li>
            </ul>
            <div class="clear"></div>
          </article>
        </div>
        
      </section>
    </section>
    <!-- /课程列表 结束 -->
    <!-- 公共分页 开始 -->
      <el-pagination
        v-show="total > 8"
        :total="total"
        :current-page.sync="current"
        :page-size="8"
        background
        align="center"
        layout="prev, pager, next"
        @current-change="getCourseFrontList"/>
    <!-- 公共分页 结束 -->
  </div>
</template>
<script>
import course from '@/api/course'

export default {
  data() {
    return {
      total: null,
      current: 1,
      courseList: null,
      oneIndex:-1,
      twoIndex:-1,
      courseQueryVo: {
        title: '',
        teacherId: '',
        subjectParentId: '',
        subjectId: '',
        status: 'Normal',
        buyCountSort: false,
        gmtCreateSort: true,
        priceSort: false
      },
      subjectParentList: null,
      subjectList: null
    }
  },
  created() {
    this.getCourseSubject()
    this.getCourseFrontList()
  },
  methods: {
    getCourseSubject() {
      course.getCourseSubject()
        .then(resp => {
          this.subjectParentList = resp.data.data.menu
        })
    },
    getCourseFrontList() {
      course.getCourseFrontList(this.current, this.courseQueryVo)
        .then(resp => {
          this.courseList = resp.data.data.list
          this.current = Number(resp.data.data.current)
          this.total = Number(resp.data.data.total)
          console.log(this.courseList==null)
        })
    },
    conditionParent(subjectParent, index) {
      this.oneIndex = index
      this.twoIndex = -1
      if (subjectParent == null) {
        this.subjectList = null
        this.courseQueryVo.subjectParentId = null
      } else {
        this.courseQueryVo.subjectParentId = subjectParent.id
        this.subjectList = subjectParent.children
      }
      this.getCourseFrontList()
    },
    conditionChild(subject, index) {
      this.twoIndex = index
      this.courseQueryVo.subjectParentId = subject.parentId
      this.courseQueryVo.subjectId = subject.id
      this.getCourseFrontList()
    },
    searchBuyCount() {
      this.courseQueryVo.buyCountSort = true
      this.courseQueryVo.gmtCreateSort = false
      this.courseQueryVo.priceSort = false
      this.getCourseFrontList()
    },
    searchGmtCreate() {
      this.courseQueryVo.buyCountSort = false
      this.courseQueryVo.gmtCreateSort = true
      this.courseQueryVo.priceSort = false
      this.getCourseFrontList()
    },
    searchPrice() {
      this.courseQueryVo.buyCountSort = false
      this.courseQueryVo.gmtCreateSort = false
      this.courseQueryVo.priceSort = true
      this.getCourseFrontList()
    }
  }
}
</script>